package eo.entityManager.locator;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;

/**
 * Locates or associates an {@link EntityManager}. Applications are responsible
 * for mantaining the transaction status.
 * 
 * @author takeshi
 * 
 */
public interface EntityManagerLocator {

    /**
     * Finds an {@link EntityManager} instance, either by creating one if
     * necessary or returning a previously created one, associated with the
     * current context, for example the current {@link Thread}. If the current
     * {@link EntityManager} is already closed, this method will clean up and
     * open a new {@link EntityManager}.
     * 
     * @return {@link EntityManager}
     */
    EntityManager findEntityManager();

    /**
     * Closes the currently associated {@link EntityManager} if any.
     */
    void closeEntityManager();

    /**
     * Gets the {@link EntityManagerFactory} used to open {@link EntityManager}
     * instances.
     * 
     * @return {@link EntityManagerFactory}
     */
    EntityManagerFactory getEntityManagerFactory();
}
